package com.xw.controller.api;

import com.xw.util.MPUtils;
import com.xw.util.PropertiesUtil;
import com.xw.util.ResponseData;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * @author wxx
 * @version 1.0
 * @date 2020/3/10 13:47
 */
@Controller
@RequestMapping("/api/authMiniProcess")
public class ApiAuthMiniProcess {


    /**
     * 解密数据
     * @param encryptedData
     * @param sessionKey
     * @param iv
     * @return
     */
    @RequestMapping("/authData")
    @ResponseBody
    public Map authData(String encryptedData,String sessionKey,String iv){
        Map map = MPUtils.authData(encryptedData, sessionKey, iv);
        return map;
    }

    /**
     *  获取用户的session_key和 OpenID
     * @param jsCode   登录时获取的 jsCode
     * @return
     */
    @RequestMapping("/jscode2session")
    @ResponseBody
    public Object getSessionKey(String jsCode){
        String appId = PropertiesUtil.getProperty("MP_APPID");
        String secret = PropertiesUtil.getProperty("MP_SECRET");
        ResponseData data = MPUtils.jscode2session(appId, secret, jsCode);
        return data;
    }

}
